package handler

import (
	"fmt"
	"choujiang/box_server/service"
	"choujiang/common/utils"
	"strconv"

	"github.com/gin-gonic/gin"
)

func GoodsList(c *gin.Context) {
	goods, err := service.GetGoodsList()
	if err != nil {
		fmt.Printf("service.GetGoodsList err:", err)
	}
	for i := 0; i < len(goods); i++ {
		goods[i].Cover = utils.AddPrefix(goods[i].Cover)
	}
	utils.JSON(goods, c)
}

func GoodsDetail(c *gin.Context) {
	form := c.Request.Form
	Id := form.Get("id")
	int64Id, _ := strconv.ParseInt(Id, 10, 64)
	goodsDetail, err := service.GetGoodsDetail(int64Id)
	if err != nil {
		fmt.Printf("GetGoodsDetail err:%+v\n", err)
	}
	utils.JSON(goodsDetail, c)
}
